<template>
  <div class="header">
    <!-- 折叠按钮 -->
    <div class="collapse-btn" @click="collapseChage">
      <i class="el-icon-menu"></i>
    </div>
    <div class="logo">社区疫情管理系统</div>
    <div class="header-right">
      <div class="header-user-con">
        <!-- 全屏显示 -->
        <div class="btn-fullscreen" @click="handleFullScreen">
          <el-tooltip
            effect="dark"
            :content="fullscreen ? `取消全屏` : `全屏`"
            placement="bottom"
          >
            <i class="el-icon-rank"></i>
          </el-tooltip>
        </div>
        <!-- 用户注销 -->
        <div class="exit" @click="Signout" style="color:#F50000;">
          <el-tooltip effect="dark" :content="`注销`" placement="bottom">
            <i class="el-icon-switch-button"></i>
          </el-tooltip>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
//import bus from './bus';
export default {
  name: "Header",
  //返回新生成的组件相关数据
  data() {
    return {
      collapse: false,
      fullscreen: false,
      name: "Gary",
    };
  },
  computed: {
    username() {
      let username = this.$common.getSessionStorage("username");
      return username ? username : this.name;
    },
  },
  methods: {
    //用户注销
    Signout() {
      this.$confirm("是否注销账户", "账户登出", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出成功!",
          });
          //触发登出状态改变
          this.$store.commit("Signout");
          this.$router.push({ name: "signin", path: "/signin" });
          console.log("Signout")
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "保留登陆",
          });
        });
    },
    // 侧边栏折叠
    collapseChage() {
      this.collapse = !this.collapse;
      // bus.$emit('collapse', this.collapse);
    },
    // 全屏事件
    handleFullScreen() {
      let element = document.documentElement;
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen();
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen();
        }
      }
      this.fullscreen = !this.fullscreen;
    },
  },
  /*mounted(){
            if(document.body.clientWidth < 1366){
                this.collapseChage();
            }
        }*/
};
</script>
<style scoped>
/* 这里是个人信息的相关css表 */

.header {
  position: relative;
  box-sizing: border-box;
  width: 1400px;
  height: 70px;
  font-size: 22px;
  color: #000;
}
.collapse-btn {
  float: left;
  padding: 0 21px;
  cursor: pointer;
  line-height: 70px;
}
.header .logo {
  float: left;
  width: 250px;
  line-height: 70px;
}
.header-right {
  float: right;
  padding-right: 50px;
}
.header-user-con {
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
  position: relative;
  width: 30px;
  height: 30px;
  text-align: center;
  border-radius: 15px;
  cursor: pointer;
}
.exit {
  margin-left: 10px;
}
.el-dropdown-menu__item {
  text-align: center;
}
</style>
